Skip to main content

Authentication

signAuthToken​

A server-side function which creates an auth token to be used to authenticate getPrices requests.

Usage​

Generating authentication tokens on the server:

import { signAuthToken } from '@chronicleprotocol/pull-oracle';

const { token, message } = await signAuthToken({
// private key is 0x prefixed 32 byte hex string
privateKey: "0xabc..."
})

Returns​

{ 
token: "...",
message: AuthTokenMessage
}

Parameters​

{ privateKey: "0xabc...", duration: 1800 }

privateKey​

  • Type: string

The privateKey for the account signing the auth token.

duration​

  • Optional
  • Default: 1800
  • Type: number

The duration of validity for the auth token in seconds.


authenticate​

A client-side function which validates and caches the auth token which was received from the server for future use with getPrices.

Usage​

import { authenticate } from '@chronicleprotocol/pull-oracle';

// token is received from the server
// `authenticate` caches the token in memory so it only needs to be called once per session
authenticate(token);

Returns​

  • boolean: whether the provided auth token is currently valid.

isAuthenticated

A function to check whether the library has a currently valid auth token previously cached by the authenticate function.

Usage​

import { isAuthenticated } from '@chronicleprotocol/pull-oracle';

// token from the cache is verified
const isAuthenticated = isAuthenticated()

Returns​

  • boolean: whether the cached auth token is currently valid.